package com.sscl.baselibrary.exts

import android.content.Context
import android.os.Build
import android.view.View
import android.view.WindowInsets
import android.view.WindowManager
import android.widget.PopupWindow

fun PopupWindow.hideNavigationBar() {
    //隐藏导航栏
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        contentView.windowInsetsController?.hide(WindowInsets.Type.navigationBars())
        contentView.windowInsetsController?.hide(WindowInsets.Type.statusBars())
        contentView.windowInsetsController?.hide(WindowInsets.Type.captionBar())
        contentView.windowInsetsController?.hide(WindowInsets.Type.systemBars())
        contentView.windowInsetsController?.hide(WindowInsets.Type.displayCutout())
        contentView.windowInsetsController?.hide(WindowInsets.Type.mandatorySystemGestures())
        contentView.windowInsetsController?.hide(WindowInsets.Type.systemGestures())
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
            contentView.windowInsetsController?.hide(WindowInsets.Type.systemOverlays())
        }
        contentView.windowInsetsController?.hide(WindowInsets.Type.tappableElement())
    } else {
        @Suppress("DEPRECATION")
        contentView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        @Suppress("DEPRECATION")
       contentView.setOnSystemUiVisibilityChangeListener {
            var uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                    //布局位于状态栏下方
                    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
                    //全屏
                    View.SYSTEM_UI_FLAG_FULLSCREEN or
                    //隐藏导航栏
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            uiOptions = uiOptions or 0x00001000
           contentView.systemUiVisibility = uiOptions
        }
    }
}